<!DOCTYPE html>
<html lang="en">
<head>
    <!-- The jQuery library is a prerequisite for all jqSuite products -->
    <script type="text/ecmascript" src="../../../js/jquery.min.js"></script> 
    <!-- This is the Javascript file of jqGrid -->   
    <script type="text/ecmascript" src="../../../js/trirand/src/jquery.jqGrid.js"></script>
    <!-- This is the localization file of the grid controlling messages, labels, etc.
    <!-- We support more than 40 localizations -->
    <script type="text/ecmascript" src="../../../js/trirand/i18n/grid.locale-en.js"></script>
    <!-- A link to a jQuery UI ThemeRoller theme, more than 22 built-in and many more custom -->
    <link rel="stylesheet" type="text/css" media="screen" href="../../../css/jquery-ui.css" />
    <!-- The link to the CSS that the grid needs -->
    <link rel="stylesheet" type="text/css" media="screen" href="../../../css/trirand/ui.jqgrid.css" />
    <meta charset="utf-8" />
    <title>jqGrid Functionality - Built-In Formatters</title>
</head>
<body>

    <table id="jqGrid"></table>
    <div id="jqGridPager"></div>

    <script type="text/javascript"> 
    
        $(document).ready(function () {
			var lastSel;
            $("#jqGrid").jqGrid({
                url: 'data.json',
                datatype: "json",
                colModel: [
                    {
                        label: 'AccessGroupId',
                        name: 'AccessGroupId',
                        key : true,
                        width: 10,
                        hidden:true

                    },                    {
                        name: 'Integer',
                        width: 75,
                        formatter: 'integer',
                        formatoptions: { defaultValue: 'No Value Set', thousandsSeparator: ',' , decimalPlaces: 0},
						editable : true
                    },
                    {
                        name: 'Number',
                        width: 90,
                        formatter: 'number',
						editable : true,
                        formatoptions :{ decimalSeparator: ".", decimalPlaces:1, thousandsSeparator:" "}
                    },
                    {
                        name: 'Currency',
                        width: 75,
						editable : true,
                        formatter: 'currency',
                        formatoptions: { decimalSeparator: '.', decimalPlaces: 1, suffix: ' USD', thousandsSeparator: ',', prefix: '$' }

                    },
					{
                        label: 'ExpiryDate',
                        name: 'ExpiryDate',
                        width: 70,
                        align: 'center',
                        formatter: 'date',
                        formatoptions: { srcformat: 'ISO8601Long', newformat: 'd/m/Y', reformatAfterEdit : true },
                        editable: true,
                        edittype: "text",
                        editoptions: {
                            // dataInit is the client-side event that fires upon initializing the toolbar search field for a column
                            // use it to place a third party control to customize the toolbar
                            dataInit: function (element) {
                                $(element).datepicker({
                                    autoclose: true,
                                    format: 'dd/mm/yy',
                                    orientation: 'auto bottom'
                                });
                            },
                        }
					},
                    {
                        name: 'Email',
                        width: 140,
						editable : true,
                        formatter: 'email'
                    },
                    {
                        name: 'Link',
                        width: 140,
						editable : true,
                        formatter: 'link',
						formatoptions : {
							target : "_blank"
						}
                    },
                    {
                        name: 'CheckBox',
                        width: 50,
						edittype : "checkbox",
						editable: true,
						editoptions : { value: "1:0"},
                        formatter: 'checkbox',
                        formatoptions: {disabled: true}
                    },
					{
                        label: "Edit Actions",
                        name: "actions",
                        width: 80,
                        formatter: "actions",
                        formatoptions: {
                            keys: true,
							onSuccess : function ( result  ) {
								console.log("Record (not) saved!");
							}, 
                            editOptions: {},
                            addOptions: {},
                            delOptions: { 
								serializeDelData : function( postdata ) {
									postdata['AccessGroupId'] = postdata.id;
									return postdata;
								}
							}
                        }
                    }
                ],
				editurl : "data.json",
				/*
                onSelectRow: function(id, status, e){
					if(id && id!==lastSel){
						jQuery('#jqGrid').jqGrid('restoreRow',lastSel);
						lastSel=id;
					}
					jQuery('#jqGrid').jqGrid('editRow', id, {keys:  true} );					
                },
				*/
				serializeRowData : function( postdata ) {
					//console.log(postdata);
					postdata['ExpiryDate'] = $.jgrid.parseDate.call(this, "d/m/Y", postdata['ExpiryDate'], "Y-m-d H:i:s");
					return postdata;
				},
                width: 800,
                height: 200,
                rowNum: 150,
				editurl: "data.json",
                pager: "#jqGridPager"
            });
var $grid = $("#jqGrid");
//... here the grid will be created
/*
$grid.closest("div.ui-jqgrid-view").find("div.ui-jqgrid-hdiv table.ui-jqgrid-htable tr.ui-jqgrid-labels > th.ui-th-column > div.ui-jqgrid-sortable")
    .each(function () {
        $('<button>').css({float: "right", height: "17px"}).appendTo(this).button({
            icons: { primary: "ui-icon-gear" },
            text: false
        }).click(function (e) {
            var idPrefix = "jqgh_" + $grid[0].id + "_",
                thId = $(e.target).closest('div.ui-jqgrid-sortable')[0].id;
            // thId will be like "jqgh_list_name"
            if (thId.substr(0, idPrefix.length) === idPrefix) {
                alert('Clicked the button in the column "' + thId.substr(idPrefix.length) + '"');
                return false;
            }
        });
    });			
	*/
});

    </script>

    <!-- This code is related to code tabs -->
    <br />
    <span style="font-size: 12px; font-family: Tahoma">Click on the Tabs below the see the relevant code for the example:</span>
    <br /><br />
    <div id="codetabs" style="width:700px; height: 400px; font-size:65%;"></div>
    <script type="text/ecmascript" src="../../../js/jquery-ui.min.js"></script>
    <script type="text/ecmascript" src="../../../js/prettify/prettify.js"></script>
    <link rel="stylesheet" href="../../../css/prettify.css" />
        <script type="text/ecmascript" src="../../../js/codetabs.js"></script><script type="text/ecmascript" src="../../../js/themeswitchertool.js"></script>
    
    <script type="text/javascript">

        var tabData =
            [
                { name: "HTML", url: "index.html", lang: "lang-html" },
                { name: "Data.JSON", url: "data.json", lang: "lang-json" },
				{ name: "Description", url: "description.html", lang: "lang-html" }
            ];

        codeTabs(tabData);

    </script>
    <!-- End of code related to code tabs -->
</body>
</html>